FROM ubuntu:16.04
LABEL Zhu Chen Tong

ENV DEBIAN_FRONTEND noninteractive

# install dependencies
RUN sed -i "s/archive.ubuntu.com/mirrors.163.com/g" /etc/apt/sources.list && \
  apt-get clean && \
  apt-get update --fix-missing  && \
  apt-get install -y --no-install-recommends \
  git \
  apt-utils \
  build-essential \
  curl \
  wget \
  unzip \
  gradle \
  openjdk-8-jdk \
  && curl -o- https://deb.nodesource.com/setup_12.x | bash - \
  && apt-get update \
  && apt-get install -y nodejs \
  && apt-get autoclean \
  && apt-get autoremove \
  && rm -rfv /var/lib/apt/lists/*


# setup android env variables
ENV ANDROID_HOME            /opt/android-sdk-linux
ENV ANDROID_SDK_ROOT        /opt/android-sdk-linux
ENV PATH                    ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools

# android sdk
ENV ANDROID_SDK_VERSION     24.4.1
RUN curl -sSL http://dl.google.com/android/android-sdk_r${ANDROID_SDK_VERSION}-linux.tgz \
  | tar -C /opt -xz \
  && chown -R root:root ${ANDROID_HOME}

# install android sdk tools
RUN echo 'y' | /opt/android-sdk-linux/tools/android update sdk -u -a -t platform-tools,build-tools-28.0.3,android-28,extra-android-support,extra-google-m2repository,extra-android-m2repository

# install nodejs & dependencies
RUN npm config set registry https://registry.npm.taobao.org && \
  npm i -g cordova ionic

COPY . /app
WORKDIR /app

# build android app
RUN npm install && \
  npm run build:android

RUN jarsigner -verbose -keystore keystore/qloud.keystore -storepass 123456 -signedjar app.apk platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk qloud.keystore
# RUN mv ./platforms/android/app/build/outputs/apk/debug/app-debug.apk /app/output




